package com.suntimes.guangjiegou.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;

import com.suntimes.guangjiegou.R;

public abstract class NavigationSubFragment extends BaseFragment {
	
	public static final String TAG = "NavigationSubFragment";
	
	private ImageButton mBtnBack;
	private ImageButton mImgBtnRight;
	private TextView mTxtTitlte;
	private boolean mIsRootFragment;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		RelativeLayout layout = (RelativeLayout)inflater.inflate(R.layout.page_navigation_sub, null, false);
		LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
		lp.addRule(RelativeLayout.BELOW, R.id.page_navigation_sub_header);
		mTxtTitlte = (TextView)layout.findViewById(R.id.page_navigation_sub_txtTitle);
		mImgBtnRight = (ImageButton)layout.findViewById(R.id.page_navigation_sub_imgBtnRight);
		View view = loadView(inflater, container, savedInstanceState);
		layout.addView(view, lp);
		
		mBtnBack = (ImageButton)layout.findViewById(R.id.page_navigation_sub_btnBack);
		if(!mIsRootFragment) {
			mBtnBack.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					getNavigationFragment().pop();
				}
				
			});
			showBackButton();
		} 
		
		return layout;
	}
	
	
	public void setTitle(String title) {
		if(mTxtTitlte != null) {
			mTxtTitlte.setText(title);
		}
	}
	
	public void setTitle(int resId) {
		if(mTxtTitlte != null) {
			mTxtTitlte.setText(resId);
		}
	}
	
	public void showBackButton() {
		mBtnBack.setVisibility(View.VISIBLE);
	}
	
	public void hideBackButton() {
		mBtnBack.setVisibility(View.GONE);
	}
	
	public void setRootFragment(boolean isRootFragment) {
		mIsRootFragment = isRootFragment;
	}
	
	public void setRightButton(int resid, OnClickListener listener) {
		mImgBtnRight.setVisibility(View.VISIBLE);
		mImgBtnRight.setImageResource(resid);
		mImgBtnRight.setOnClickListener(listener);
	}
	
}
